package com.zzyl.nursing.controller.member;

import cn.hutool.db.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.dto.ProjectQueryDto;
import com.zzyl.nursing.service.ProjectService;
import com.zzyl.nursing.vo.ProjectVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags ="护理服务查询")
@RestController
@RequestMapping("/member/orders/project")
public class ProjectControllerApi {
    @Autowired
    private ProjectService  projectService;
    @GetMapping("/page")
    public AjaxResult getProjects(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status) {

        LambdaQueryWrapper<NursingProject> queryWrapper = new LambdaQueryWrapper<>();
        if (name != null && !name.isEmpty()) {
            queryWrapper.like(NursingProject::getName, name);
        }
        if (status != null) {
            queryWrapper.eq(NursingProject::getStatus, status);
        }
        queryWrapper.orderByAsc(NursingProject::getOrderNo);

        Page<NursingProject> page = new Page<>(pageNum, pageSize);
        projectService.page(page, queryWrapper);

        // 构造小程序能识别的数据格式
        return AjaxResult.success()
                .put("total", page.getTotal())
                .put("rows", page.getRecords());
    }


    @GetMapping("/{id}")
    public AjaxResult getProjectById(@PathVariable Long id) {
        NursingProject project = projectService.getById(id);
        return AjaxResult.success(project);

    }



}
